<template>
    <view class="indexs">
        <view class="header header_lan" :style="'padding-top: ' + navH + 'px;'">
            <view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
                <view class="index_h_cont3">
                    <view class="index_wenben_img" @tap="jumpzuo">
                        <image :src="imgUrl+'/dzx_img22.png'" mode="widthFix"></image>
                    </view>
                    <view class="index_wenben baise">{{ $t('page_worker_edit.Edit_permission') }}</view>
                </view>
            </view>
            <view class="coloe_title">s</view>
        </view>
        <view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom: 130rpx;'">
            <view class="dizhi_add_center">
					<view class="dizhi_add_list">
					        <view class="dizhi_add_cont">
					            <view class="dizhi_add_cont_t1"><span class="bitian"> * </span>{{ $t('page_worker_edit.name') }}</view>
					            <view class="dizhi_add_cont_r">
					                <input type="text" :placeholder="$t('page_worker_edit.placeholder1')" :value="detail.real_name" @input="usernameFun" />
					            </view>
					        </view>

					        <view class="dizhi_add_cont" >
					            <view class="dizhi_add_cont_t1"><span class="bitian"> * </span>{{ $t('page_worker_edit.phone') }}</view>
					            <view class="dizhi_add_cont_r">
					                <input type="text" :placeholder="$t('page_worker_edit.placeholder2')" :value="detail.mobile" @input="telcodeFun" />
					            </view>
					        </view>
					        <view class="dizhi_add_cont">
					            <view class="dizhi_add_cont_t1"><span class="bitian"> * </span>{{ $t('page_worker_edit.Account_status') }}</view>
					            <view class="dizhi_add_cont_r">
					                <picker @change="bindPickerChange" :value="cindex" :range="cangkuarray">
					                    <view class="baoguo_item2_cont_r">
					                        <text>{{ cangkuarray[cindex] }}</text>
					                        <image :src="imgUrl+'/dzx_img25.png'"></image>
					                    </view>
					                </picker>
					            </view>
					        </view>
							<view class="dizhi_add_cont">
							    <view class="dizhi_add_cont_t1"><span class="bitian"> * </span>{{ $t('page_worker_edit.Message_reception') }}</view>
							    <view class="dizhi_add_cont_r">
							        <picker @change="bindPickerChangeMesaage" :value="mindex" :range="message">
							            <view class="baoguo_item2_cont_r">
							                <text>{{ message[mindex] }}</text>
							                <image :src="imgUrl+'/dzx_img25.png'"></image>
							            </view>
							        </picker>
							    </view>
							</view>
							<view class="dizhi_add_conts">
							    <view class="dizhi_add_cont_t1"><span class="bitian"> * </span>{{ $t('page_worker_edit.hint') }}</view>
							    <view class="dizhi_add_cont_rr">
									<view class="uni-form-item uni-column" v-for="(item,index) in detail.cherkAr"   >
										<label :data-index="index"  @touchend="CheckChange">
											<checkbox :checked="item.is_pre" :data-index="index" type="checkbox"  />
											<text>{{item.text}}</text>
										</label>
									</view>
							    </view>
							</view>

					    </view>
					    <view class="dizhi_add_btn">
					        <view class="dizhi_add_btns" @tap="baocun">{{ $t('page_worker_edit.save') }}</view>
					    </view>
					</view><strong></strong>
            </view>
        </view>
    </view>
</template>
<script>
const app = getApp();
let request = require('../../../../utils/require');

	export default {
		data() {
			return {
				navH: app.globalData.navHeight,
				gaodu: app.globalData.height,
				gaodutops: app.globalData.top,
				imgUrl:app.globalData.imgUrl,
				height: 0,
				heights: 0,
				cindex:0,
				mindex:0,
				detail:'',
				realname:'',
				mobile:'',
				cangkuarray: [
					'禁用',
					'启用'
				],
				cherkAr:'',
				message:['接收','不接收']
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
		    var that = this;
		    that.id=options.id
			
			that.getClerkDetail();
		},
		onShow() {
		    var that = this;
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function () {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function () {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function () {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function () {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function () {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function () {},
		methods: {
			//更改状态
			CheckChange(e){
				var that = this;
				var index = e.currentTarget.dataset.index;
				var cherkAr2 = that.cherkAr;
				console.log(index,999)
				if(cherkAr2[index]['is_pre']==true){
					that.cherkAr[index]['is_pre'] = 0;
				}else{
					that.cherkAr[index]['is_pre'] = 1;
				}
				
			},
			//选择状态
			bindPickerChange: function (e) {
			    this.cindex= e.detail.value
			},
			//选择状态
			bindPickerChangeMesaage: function (e) {
			    this.mindex= e.detail.value
			},
			usernameFun(e) {
			    this.realname= e.detail.value
			},
			baocun(e) {
			    var that = this;
				var data = {
					clerk_id: that.id,
					realname:that.realname,
					mobile:that.mobile,
					status:that.cindex,
					mes_status:that.mindex,
					cherkAr:that.cherkAr,
					token: uni.getStorageSync('token')
				};
				request.post(`index.php?s=/api/shop.clerk/editClerk&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
					if (res.data.code == 1) {
						uni.showToast({
							title: res.data.data
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 0
							});
						}, 1000);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
					}
				});
			},
			getClerkDetail(){
				var that = this;
				var data = {
					token: uni.getStorageSync('token'),
					id:that.id
				};
				request.get(`index.php?s=/api/shop.clerk/getClerkDetail&wxapp_id=` + uni.getStorageSync('web_id'), data).then((res) => {
					if (res.data.code == 1) {
						this.detail = res.data.data;
						this.cindex = res.data.data.status;
						this.mindex = res.data.data.mes_status;
						this.realname = res.data.data.real_name;
						this.mobile = res.data.data.mobile;
						this.cherkAr = res.data.data.cherkAr
					}
				});
			},
			jumpzuo() {
			    uni.navigateBack()
			}
		}
	}
</script>

<style>
	@import './worker_edit.css';
</style>
